//
//  WBHomeCell.swift
//  微博Demo
//
//  Created by 花化华 on 2016/11/27.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class WBHomeCell: WBBaseTableViewCell {

    /// 原创微博
    let originalView: WBOriginalView = WBOriginalView()
    
    /// 转发微博
    let retweetedView: WBRetweetedView = WBRetweetedView()
    
    /// toolBar
    let homeToolBar: WBHomeToolBar = WBHomeToolBar()

    /// 视图模型
    var homeViewModel: WBHomeViewModel? {
        didSet {
            //将视图模型传递给 originalView和retweetedView
            originalView.statusViewModel = homeViewModel
            retweetedView.statusViewModel = homeViewModel
        }
    }
    
    override func wbSetupSubCell() {
        super.wbSetupSubCell()
        setupUI()
    }

}

// MARK: - 设置UI
extension WBHomeCell {
    func setupUI() {
        //设置背景色
        contentView.backgroundColor = lightColour
        
        //添加子视图
        contentView.addSubview(originalView)
        contentView.addSubview(retweetedView)
        contentView.addSubview(homeToolBar)
        
        //自动布局
        originalView.snp.makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            make.top.equalTo(contentView).offset(5)
        }
        
        retweetedView.snp.makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            make.top.equalTo(originalView.snp.bottom)
        }
        
        homeToolBar.snp.makeConstraints { (make) in
            make.height.equalTo(36)
            make.left.right.equalTo(contentView)
            make.top.equalTo(retweetedView.snp.bottom)
        }
    }
}
